using System;
using System.Collections.Generic;
using System.Text;

using System.Drawing;
using System.Drawing.Drawing2D;

using System.Windows.Forms;
using System.ComponentModel;

namespace Athena.Tools
{
    public class INonVisualTool : ITool
    {
        protected bool _bHasContextMenuItems = false;

        /// <summary>
        /// the order where this tool will be places
        /// </summary>
        public virtual ToolManager.Order Order
        {
            get { return ToolManager.Order.BACK; }
        }

        /// <summary>
        /// ToolStrip that buttons belong to ...
        /// </summary>
        protected ToolStrip _oStrip = null;

        /// <summary>
        /// Has the tool items to add to the context menu (when right clicked upon in the visual window)
        /// </summary>
        [Browsable(false)]
        public bool HasContextMenuItems
        {
            get
            {
                return _bHasContextMenuItems;
            }
            set
            {
                _bHasContextMenuItems = value;
            }
        }

        protected bool _bHasMenuItems = false;
        /// <summary>
        /// Has the tool menu items to add into the tool window
        /// </summary>
        [Browsable(false)]
        public virtual bool HasMenuItems
        {
            get
            {
                return _bHasMenuItems;
            }
        }

        protected bool _bRequiresNewToolWindow = false;
        /// <summary>
        /// Has the tool menu items to add into a separate tool window
        /// </summary>
        [Browsable(false)]
        public bool RequiresNewToolWindow
        {
            get
            {
                return _bRequiresNewToolWindow;
            }
            set
            {
                _bRequiresNewToolWindow = value;
            }
        }

        public virtual void SetupContextMenu(ToolStripMenuItem oStrip)
        {

        }

        public virtual void SetupToolStrip(ToolStrip oStrip)
        {
            _oStrip = oStrip;
        }

        public virtual bool Handles(List<Type> oTypes)
        {
            return false;
        }

        protected static Model CurrentModel = Program.Model;


        public virtual void OnMouseMove(HandledMouseEventArgs e)
        {

        }

        public virtual void OnMouseUp(HandledMouseEventArgs e)
        {

        }
        public virtual void OnItemDoubleClick(HandledMouseEventArgs e)
        {
        }

        public virtual void OnMouseDown(HandledMouseEventArgs e)
        {
        }


        public virtual void OnKeyDown(KeyEventArgs args)
        {

        }

        public virtual void OnKeyUp(KeyEventArgs args)
        {

        }


        protected bool _bIsActive;

        protected static void UncheckAllButtons(ToolStripButton oCurrentButton)
        {
            if (oCurrentButton.Owner != null)
            {
                foreach (object item in oCurrentButton.Owner.Items)
                {
                    if (item is ToolStripButton)
                    {
                        ToolStripButton toolStripButton = (ToolStripButton)item;
                        toolStripButton.Checked = false;
                    }
                }
            }
            oCurrentButton.Checked = true;
        }

        protected void UncheckAllButtons()
        {
            if (_oStrip != null)
            {
                foreach (ToolStripButton button in _oStrip.Items)
                {
                    button.Checked = false;
                }
            }

        }

        [Browsable(false)]
        public bool IsActive
        {
            get
            {
                return _bIsActive;
            }
            set
            {
                
                if (_bIsActive == value) return;
                _bIsActive = value;
                if (value)
                {
                    OnActivate();
                    ToolManager.Instance.NotifyActivateTool(this);
                }
                else
                {
                    OnDeactivate();
                    ToolManager.Instance.NotifyDeactictivateTool(this);
                }                
            }
        }

        internal void KeepActive()
        {            
            _bIsActive = true;
            OnActivate();
        }
        internal void KeepDeactive()
        {
            _bIsActive = false;
            OnDeactivate();
        }

        /// <summary>
        /// called when tool is activated
        /// </summary>
        public virtual void OnActivate()
        {

        }
        /// <summary>
        /// Called when Tool is deactivated
        /// </summary>
        public virtual void OnDeactivate()
        {

        }

        public virtual void OnSelectionChanged()
        {

        }

    }
}
